import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'


import {viteObfuscateFile} from 'vite-plugin-obfuscator'
// import obfuscatorPlugin from 'rollup-plugin-javascript-obfuscator'
import { resolve } from 'path'

export default defineConfig({

  //打包部署后禁止用户控制台sources看到源码
  productionSourceMap: false,
  //打包加密
  plugins: [
    vue(),
    viteObfuscateFile({
      compact: true,
      controlFlowFlattening: false,
      controlFlowFlatteningThreshold: 0.75,
      deadCodeInjection: true,
      deadCodeInjectionThreshold: 0.4,
      debugProtection: true,
      debugProtectionInterval: 1,
      disableConsoleOutput: false,
      domainLock: [],
      domainLockRedirectUrl: 'about:blank',
      forceTransformStrings: [],
      identifierNamesCache: null,
      identifierNamesGenerator: 'hexadecimal',
      identifiersDictionary: [],
      identifiersPrefix: '',
      ignoreImports: false,
      inputFileName: '',
      log: false,
      numbersToExpressions: false,
      optionsPreset: 'default',
      renameGlobals: false,
      renameProperties: false,
      renamePropertiesMode: 'safe',
      reservedNames: [],
      reservedStrings: [],
      seed: 0,
      selfDefending: false,
      simplify: true,
      sourceMap: false,
      sourceMapBaseUrl: '',
      sourceMapFileName: '',
      sourceMapMode: 'separate',
      sourceMapSourcesMode: 'sources-content',
      splitStrings: false,
      splitStringsChunkLength: 10,
      stringArray: true,
      stringArrayCallsTransform: true,
      stringArrayCallsTransformThreshold: 0.5,
      stringArrayEncoding: [],
      stringArrayIndexesType: [
        'hexadecimal-number'
      ],
      stringArrayIndexShift: true,
      stringArrayRotate: true,
      stringArrayShuffle: true,
      stringArrayWrappersCount: 1,
      stringArrayWrappersChainedCalls: true,
      stringArrayWrappersParametersMaxCount: 2,
      stringArrayWrappersType: 'variable',
      stringArrayThreshold: 0.75,
      target: 'browser',
      transformObjectKeys: false,
      unicodeEscapeSequence: true
    })
    // apply: 'build' // 仅在生产环境下使用

  ],
  server: {
    host: '0.0.0.0',//解决vite use--host to expose
    port: 8080,
    open: true
  },

  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, 'src')
      }
    ]
  },

})
